//
//  CommanMacro.h
//  ThunderChat
//
//  Created by Kelly xu on 2018/10/16.
//  Copyright © 2018年 Simubang. All rights reserved.
//

#ifndef CommanMacro_h
#define CommanMacro_h

#define dispatch_sync_main_safe(block)\
if ([NSThread isMainThread]) {\
block();\
} else {\
dispatch_sync(dispatch_get_main_queue(), block);\
}

#define dispatch_async_main_safe(block)\
if ([NSThread isMainThread]) {\
block();\
} else {\
dispatch_async(dispatch_get_main_queue(), block);\
}

#define PlaceholderImage [UIImage imageNamed:@"appIconNew1024"]
#define SmallListDefaultImg [UIImage imageNamed:@"defaultImg_small"]
#define BigListDefaultImg [UIImage imageNamed:@"defaultImg_big"]

#define Toast(__str) [KeyWindow makeToast:__str duration:1.0 position:CSToastPositionCenter]

#define Color(__url) [UIColor colorWithHexString:__url]
#define TCImageNamed(__imageName) [UIImage imageNamed:__imageName]
//颜色
#define DefaultImageBgColor Color(@"cccccc")
#define ThemeColor Color(@"65AAF9")
#define LightGrayColor Color(@"DFE0E2")
#define BackGroundColor Color(@"f8f8f8")
// 获取当前app版本号
#define appCurrentVersion  [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]

// 状态栏隐藏
#define STATUSBAR_HIDDEN  [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationFade];

// 状态栏显示
#define STATUSBAR_SHOW   [[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationFade];

#define StatusBarHeight (isIphoneX?44:20)
#define BottomSafeAreaHeight (isIphoneX?PhoneXBottomSafeAreaHeight:0)
#define PhoneXBottomSafeAreaHeight [[UIApplication sharedApplication].windows objectAtIndex:0].safeAreaInsets.bottom

#define isIphoneX ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1125, 2436), [[UIScreen mainScreen] currentMode].size) : NO) || ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1242, 2688), [[UIScreen mainScreen] currentMode].size) : NO) || ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(828, 1792), [[UIScreen mainScreen] currentMode].size) : NO)
//
// 屏幕尺寸
//
#define DEVICE_BOUNDS [UIScreen mainScreen].bounds

#define DEVICE_WIDTH [UIScreen mainScreen].bounds.size.width

#define DEVICE_HEIGHT [UIScreen mainScreen].bounds.size.height

//版本号
#define OSVersion [[UIDevice currentDevice] systemVersion]
#define appShortVersion [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]
#define ApplicationDelegate   ((AppDelegate *)[[UIApplication sharedApplication] delegate])
#define KeyWindow           [[[UIApplication sharedApplication] delegate] window]
// 字体 4s 4 5 5s 5c与6以上区别 以6为基准
#define PingFangSCRegular @"PingFangSC-Regular"
#define PingFangSCMedium @"PingFangSC-Medium"
#define GMFONTSCALE(orginFont) DEVICE_HEIGHT > 568 ? (DEVICE_HEIGHT > 667 ? (orginFont) : (orginFont)) : (orginFont - 2)
#define font11 [UIFont systemFontOfSize:GMFONTSCALE(11)]
#define font12 [UIFont systemFontOfSize:GMFONTSCALE(12)]
#define font13 [UIFont systemFontOfSize:GMFONTSCALE(13)]
#define font14 [UIFont systemFontOfSize:GMFONTSCALE(14)]
#define font15 [UIFont systemFontOfSize:GMFONTSCALE(15)]
#define font16 [UIFont systemFontOfSize:GMFONTSCALE(16)]
#define font17 [UIFont systemFontOfSize:GMFONTSCALE(17)]
#define font18 [UIFont systemFontOfSize:GMFONTSCALE(18)]
#define font19 [UIFont systemFontOfSize:GMFONTSCALE(19)]
#define font20 [UIFont systemFontOfSize:GMFONTSCALE(20)]
#define font21 [UIFont systemFontOfSize:GMFONTSCALE(21)]
#define font22 [UIFont systemFontOfSize:GMFONTSCALE(22)]
#define font23 [UIFont systemFontOfSize:GMFONTSCALE(23)]
#define font24 [UIFont systemFontOfSize:GMFONTSCALE(24)]
#define font25 [UIFont systemFontOfSize:GMFONTSCALE(25)]
#define font26 [UIFont systemFontOfSize:GMFONTSCALE(26)]
#define font27 [UIFont systemFontOfSize:GMFONTSCALE(27)]
#define font28 [UIFont systemFontOfSize:GMFONTSCALE(28)]
#define font29 [UIFont systemFontOfSize:GMFONTSCALE(29)]
#define font30 [UIFont systemFontOfSize:GMFONTSCALE(30)]
#define font39 [UIFont systemFontOfSize:GMFONTSCALE(39)]
#define font40 [UIFont systemFontOfSize:GMFONTSCALE(40)]
#define font42 [UIFont systemFontOfSize:GMFONTSCALE(42)]
#define ResentMonReturnTableViewCellHIGHT 70

#define boldfont11 [UIFont boldSystemFontOfSize:GMFONTSCALE(11)]
#define boldfont13 [UIFont boldSystemFontOfSize:GMFONTSCALE(13)]
#define boldfont14 [UIFont boldSystemFontOfSize:GMFONTSCALE(14)]
#define boldfont15 [UIFont boldSystemFontOfSize:GMFONTSCALE(15)]
#define boldfont16 [UIFont boldSystemFontOfSize:GMFONTSCALE(16)]
#define boldfont17 [UIFont boldSystemFontOfSize:GMFONTSCALE(17)]
#define boldfont18 [UIFont boldSystemFontOfSize:GMFONTSCALE(18)]
#define boldfont19 [UIFont boldSystemFontOfSize:GMFONTSCALE(19)]
#define boldfont20 [UIFont boldSystemFontOfSize:GMFONTSCALE(20)]
#define boldfont21 [UIFont boldSystemFontOfSize:GMFONTSCALE(21)]
#define boldfont22 [UIFont boldSystemFontOfSize:GMFONTSCALE(22)]
#define boldfont23 [UIFont boldSystemFontOfSize:GMFONTSCALE(23)]
#define boldfont24 [UIFont boldSystemFontOfSize:GMFONTSCALE(24)]
#define boldfont25 [UIFont boldSystemFontOfSize:GMFONTSCALE(25)]
#define boldfont28 [UIFont boldSystemFontOfSize:GMFONTSCALE(28)]
#define boldfont30 [UIFont boldSystemFontOfSize:GMFONTSCALE(30)]
#define boldfont32 [UIFont boldSystemFontOfSize:GMFONTSCALE(32)]
#define boldfont34 [UIFont boldSystemFontOfSize:GMFONTSCALE(34)]
#define boldfont40 [UIFont boldSystemFontOfSize:GMFONTSCALE(40)]

//====================================================
// 用途: block
//====================================================
#define kWeakSelf  __weak typeof(self) weakSelf = self
#define kWeak(__obj) __weak typeof(__obj) weakSelf = __obj
#define kStrongSelf __strong __typeof(weakSelf) strongSelf = weakSelf
#define kStrong(__weakSelf) __strong __typeof(__weakSelf) strongSelf = __weakSelf

//====================================================
// 用途: 引用相关
//====================================================
#define PROPERTY_WEAK @property(weak,nonatomic) IBOutlet
#define PROPERTY_STRONG @property(nonatomic,strong)
#define PROPERTY_COPY_READONLY @property (nonatomic, copy, readonly)
#define PROPERTY_COPY_READWRITE @property (nonatomic, copy, readwrite)
#define PROPERTY_STRONG_READONLY @property (nonatomic, strong, readonly)
#define PROPERTY_STRONG_READWRITE @property (nonatomic, strong, readwrite)
#define PROPERTY_COPY @property(nonatomic,copy)
#define PROPERTY_UNSAFE @property(nonatomic,unsafe_unretained)
#define PROPERTY_ASSIGN @property(nonatomic,assign)

//
// 字符串判断
//

#define EC_ISNullStr(originalStr) (!originalStr || [originalStr isKindOfClass:[NSNull class]] || [originalStr isEqualToString:@"(null)"] || [[originalStr stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] length]==0 || originalStr == nil)

#ifdef DEBUG
#define DebugLog( s, ... ) printf( "<%s:(%d)> %s %s\n\n", [[[NSString stringWithUTF8String:__FILE__] lastPathComponent] cStringUsingEncoding:NSUTF8StringEncoding], __LINE__,__func__, [[NSString stringWithFormat:(s), ##__VA_ARGS__] cStringUsingEncoding:NSUTF8StringEncoding])
#else
#define DebugLog( s, ... )
#endif

#define  adjustsScrollViewInsets(scrollView)\
do {\
_Pragma("clang diagnostic push")\
_Pragma("clang diagnostic ignored \"-Warc-performSelector-leaks\"")\
if ([scrollView respondsToSelector:NSSelectorFromString(@"setContentInsetAdjustmentBehavior:")]) {\
NSMethodSignature *signature = [UIScrollView instanceMethodSignatureForSelector:@selector(setContentInsetAdjustmentBehavior:)];\
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:signature];\
NSInteger argument = 2;\
invocation.target = scrollView;\
invocation.selector = @selector(setContentInsetAdjustmentBehavior:);\
[invocation setArgument:&argument atIndex:2];\
[invocation retainArguments];\
[invocation invoke];\
}\
_Pragma("clang diagnostic pop")\
} while (0)

#define IdentifyTableViewHeight DEVICE_HEIGHT-StatusBarHeight-44-BottomSafeAreaHeight
#define IdentifyTableViewHeightWithOutToolbar DEVICE_HEIGHT-StatusBarHeight-44-BottomSafeAreaHeight
#define IdentifyTableViewHeightNoSafeBottom DEVICE_HEIGHT-StatusBarHeight-44
#define IdentifyTableViewHeightWithOutToolbarNoSafeBottom DEVICE_HEIGHT-StatusBarHeight-44

#endif /* CommanMacro_h */
